# coding:utf-8
import requests, re

headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
           'Accept-Encoding': 'gzip, deflate, sdch',
           'Accept-Language': 'zh-CN,zh;q=0.8',
           'Cache-Control':'max-age=0',
           'Connection': 'keep-alive',
           'Host':'passport.ncuhome.cn',
           'Upgrade-Insecure-Requests':'1',
           'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36', }


url = "http://passport.ncuhome.cn/NewXZZX/PCGuard/2015/order-phone.aspx"

def pcguard():
    """抓取电脑卫队预约剩余名额"""
    try:
        r = requests.get(url,headers=headers)
    except:
        return False

    r.encoding = "utf-8"
    match = re.compile("var string = (\d)") #正则匹配
    num = int(match.findall(r.text)[0])
    return num